package com.chinasofti.method2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestMethodDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
        //invoke
        Class clazz = Class.forName("com.chinasofti.ref.method2.Student");
        //获取私有方法
        Method method = clazz.getMethod("function4",String.class);

        //创建student对象
        Student student = (Student)clazz.newInstance();
        //运行方法
        Object result = method.invoke(student,"zhangsan");
        //打印一下返回值
        System.out.println(result);
    }
}